
//注册页面，隐藏登录框
//$(".lgBut").hide();
//$(".regbut").show();
    
init();

function init(){
	initbtn();
}

function initbtn(){
	//点击发送验证码
	$('#mobileBut').click(function () {
		$(".tip-box").hide();
		var dynamicPhone = $("#dynamicPhone").val();  //手机号
		
		if(dynamicPhone == ""){
			//手机号不能为空
			$(".tip-phone-null").show();
			$("#dynamicPhone").focus();
			return false;
		}
		
		if(!(/^1[3|5|7|8|9]\d{9,9}$/.test(dynamicPhone))){
			//手机格式不对
			$(".tip-phone-true").show();
			$("#dynamicPhone").focus();
			return false;
		}
			//开始获取短信验证码-------------------
			getPhoneCode();  
	});
	
	//注册按钮
	$("#register-btn").click(function(){
		$(".tip-box").hide();
		var dynamicPhone = $("#dynamicPhone").val();  //手机号
		var code=$("#code").val();
		var email=$("#email").val();
		
		
		if(dynamicPhone == ""){
			//手机号不能为空
			$(".tip-phone-null").show();
			$("#dynamicPhone").focus();
			return false;
		}
		
		if(!(/^1[3|5|7|8|9]\d{9,9}$/.test(dynamicPhone))){
			//手机格式不对
			$(".tip-phone-true").show();
			$("#dynamicPhone").focus();
			return false;
		}
		if(code==""){
			$(".tip-code").show();
			$("#code").focus();
			return false;
		}
		if(email==""){
			$(".tip-email").show();
			$("#email").focus();
			return false;
		}
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
			$(".tip-email-check").show();
			$("#email").focus();
			return false;
		}
		
		var param = {
				url:'auth/regist',
				ajaxType:'POST',
				code: code,
				email: email,
				phone:dynamicPhone,
				ticket: ""
		}

		doInvoke(param,function(data){
	    if(data.code == "10000"){
	      setMyCookie('accessToken',data.data);
	      succFunAlert("注册成功！",function(){
					//变更状态显示
		      checkLogin();
	    	  window.location.href='/#/order_list';
	      });
	    }else{
	      errorAlert(data.message);
	    }
		});
		
		
	});
	
	
	
}





/**
 * 获取短信验证码-----------start ------
 */
function getPhoneCode(result){
	 
	 var object = '';
		 countDown(60, $("#mobileBut"));
		 object = $("#dynamicPhone").val();
	 
	 var param = {
				url:'message/msg',
				ajaxType:'POST',
				code:'SMS_133405031', 
				extract:'',
				mobile: $("#dynamicPhone").val(),
				params:'',
				type :0
		}

		doInvoke(param,function(data){
//	    if(data.code == code0000){
//	    }else{
//	      errorAlert(data.message);
//	    }
//			$("#code").val(data.code);
			
		});
}	
// 获取短信验证码----------- end ------



/**
 * 输入手机号时检测手机号是否注册过
 */
function checkPhone(){
		if($("#dynamicPhone-kh").val().length == 11 && (/^1[3|5|7|8|9]\d{9,9}$/.test($("#dynamicPhone-kh").val()))){
			$.ajax({
 				type : "post",
 				data :{
 					'phone' : $("#dynamicPhone-kh").val()
 				},
 				url : '/free/check.do',
 				success : function(data) {
 					if(data.code == '0000'){//手机号未注册
	 						$("#rgbut1-goLogin").hide();
 							$("#rgbut1").show();
 							$("#mobileBut-kh").show();
 							$("#registeredTip-kh").hide();
 						
 					}else if(data.code == "1000"){//手机号已注册
 							$("#rgbut1-goLogin").show();
 							$("#rgbut1").hide();
 							$("#mobileBut-kh").hide();
 							$("#registeredTip-kh").show();
 						
 					}
 				},
 				error : function(data) {
 					
 				}
 			});
		}else{
				$("#rgbut1-goLogin").hide();
				$("#rgbut1").show();
				$("#mobileBut-kh").show();
				$("#registeredTip-kh").hide();
		}
		

};	



	  
	 

//回车键
function handleEnter(event){
	  if (event.keyCode == "13") {//keyCode=13是回车键
		  getVerifyCode();
      }
};
//回车键下一步
function enrollEnter(event){
	  if (event.keyCode == "13") {//keyCode=13是回车键
		  isShow(3);
      }
};
//回车键确认密码
function passwEnter(event){
	  if (event.keyCode == "13") {//keyCode=13是回车键
		  registerSys();
      }
};